package com.test.ssss;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Dayin {
    static Dayin dayin = new Dayin();
    static AtomicInteger atomicInteger = new AtomicInteger(0);
    static Lock lock = new ReentrantLock();

    static void aVoid(int i) {

        System.out.println(Thread.currentThread().getName() + "循环打印" + i);

    }

    public static void main(String[] args) {
        a a = new a();
        b b = new b();
        c c=new c();
        Thread thread = new Thread(a);
        Thread thread1 = new Thread(b);
        Thread thread2 = new Thread(c);
        thread.start();
        thread1.start();
        thread2.start();
    }

    static class a implements Runnable {

        @Override
        public void run() {
            for (int i=0; i < 100; ) {
                if (atomicInteger.get()==0) {
                    Dayin.aVoid(atomicInteger.get());
                    atomicInteger.set(1);
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }


        }
    }

    static class b implements Runnable {


        @Override
        public void run() {
            for (int i=0; i < 100; ) {
                if (atomicInteger.get()==1) {
                    Dayin.aVoid(atomicInteger.get());
                    atomicInteger.set(2);
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }


        }
    }
    static class c implements Runnable {


        @Override
        public void run() {
            for (int i=0; i < 100; ) {
                if (atomicInteger.get()==2) {
                    Dayin.aVoid(atomicInteger.get());
                    atomicInteger.set(0);
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }


        }
    }
}
